/*
 * $Id: $
 */
package org.rcgwt.client.ui.grid.internal.js;

/**
 * 
 * @author Olivier Oeuillot (latest modification by $Author: $)
 * @version $Revision: $ $Date: $
 */
public class JsArray<T> {

    private int count;

    /**
     * Gets the object at a given index.
     * 
     * @param index
     *            the index to be retrieved
     * @return the object at the given index, or <code>null</code> if none
     *         exists
     */
    public final native T get(int index) /*-{
        return this[index];
    }-*/;

    /**
     * Gets the length of the array.
     * 
     * @return the array length
     */
    public final native int length() /*-{
        return count;
    }-*/;

    /**
     * Sets the object value at a given index.
     * 
     * If the index is out of bounds, the value will still be set. The array's
     * length will be updated to encompass the bounds implied by the added
     * object.
     * 
     * @param index
     *            the index to be set
     * @param value
     *            the object to be stored
     */
    public final native void set(int index, T value) /*-{
        if (this[index]) {
            count--;
        }
        
        this[index] = value;
        
        if (value!=null) {
            count++;
        }
            
    }-*/;
}
